<?php
function getParamValue($param,$default_value=""){
	if(isset($param)&&!empty($param)){
		return isset($_GET[$param])?$_GET[$param]:$default_value;
	}
	return $default_value;
}

function getStr($vars,$param,$default_value=""){
	if(empty($vars)){
		return $default_value;
	}
	if(isset($vars[$param])){
		return $vars[$param];
	}

	return $default_value;
}

function page_modifier_options($option_array,$selected_option=""){
	if($selected_option==""){
		$selected_option = "-99";
	}
	$option_str ="";	
	foreach($option_array as $k=>$v){
		$option_str .="<option value='".$k."'";	
		if($selected_option == $k){
			$option_str .=" selected ";	
		}
		$option_str .=">".$v."</option>";	
	}
	return 	$option_str;
}

function page_modifier_options_ext($option_array,$selected_option=""){
	if($selected_option==""){
		$selected_option = "-99";
	}
	$select_lang= Common::_t('page_select');
	$option_str ="<option value='-1'";
	if($selected_option == -1){
		$option_str .=" selected ";	
	}
	$option_str .=">".$select_lang."</option>";
	foreach($option_array as $k=>$v){
		$option_str .="<option value='".$k."'";	
		if($selected_option == $k){
			$option_str .=" selected ";	
		}
		$option_str .=">".$v."</option>";	
	}
	return 	$option_str;
}

function page_modifier_radios($radio_name,$radios_array,$checked_option){
	$radio_str="";
	foreach($radios_array as $k=>$v){
		$radio_str.="<input type=\"radio\" name=\"".$radio_name."\" value=\"".$k."\"";	
		if($checked_option==$k){
			$radio_str.=" checked ";		
		}	
		$radio_str.=">".$v."";		
		$radio_str.="<br>";		
	}
	
	return 	$radio_str;
}

function page_modifier_checkboxs($check_name,$check_array,$checked_option,$br_index){
	$checkbox_str="";
	$i=0;
	$check_option_array = array();
	if(!empty($checked_option)){
		$check_option_array=explode(',',$checked_option);
	}
	foreach($check_array as $k=>$v){
		$i++;
		$checkbox_str.="<input type=\"checkbox\" name=\"".$check_name."[]\" value=\"".$k."\"";	
		if(in_array($k,$check_option_array)){
			$checkbox_str.=" checked ";		
		}	
		$checkbox_str.=">".$v."";	
		if($i%$br_index==0){
			$checkbox_str.="<br>";		
		}	
	}
	
	return 	$checkbox_str;
}

function page_date($param){
	if(isset($param)&&$param!=0){
		return 	date('Y-m-d',$param);
	}
	return '';
}

function page_date_His($param){
	if(isset($param)&&$param!=0){
		return 	date('Y-m-d H:i:s',$param);
	}
	return '';
}


function getLangStr($str, $lang = '')
{
	if (empty($str)) {
		return '';
	}
	if (strpos($str, '<lang') === false) {
		return $str;
	}
	if (empty($lang)) {
		$lang = 'zh_cn';
	}
	if(preg_match('/<lang='.$lang.'>(?<get>[\s\S]*?)<\/lang>/i',$str,$matches))
	{
		$ret = $matches['get'];
	}
	else
	{
		$ret = '';
	}

	return $ret;
}

function filterUrl($url_info){
	if($url_info['link_type']==PURE_LINK){
		$url = $url_info['url'];
	}else{
		$url = $url_info['url'].'_'.$url_info['id'].'.htm';
	}
	return $url;
}
?>